#ifndef __WINDOW_STUFF
#define __WINDOW_STUFF

/*
 *   This file is part of ed_pvr.
 *
 *   ed_pvr is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 2 of the License, or
 *   (at your option) any later version.
 *
 *   ed_pvr is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with ed_pvr.  If not, see <http://www.gnu.org/licenses/>.
 */

#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <stdint.h>
#include <ncurses.h>
#include <pthread.h>
#include "device.h"

#define WIN_MAX_WINDOWS			50
#define MAX_CURSES_STR_LEN		12000
struct ncurses_window_opts
{
	int x;
	int y;
	int h;
	int w;
	int draw_box;
};
typedef struct ncurses_window_opts NCURSES_WINDOW_OPTS;


struct ncurses_window
{
	pthread_mutex_t update_lock;
	WINDOW *handle;
	NCURSES_WINDOW_OPTS opts;
	uint32_t id;
	uint32_t used[10];
	void *extra_data[5];
};
typedef struct ncurses_window NCURSES_WINDOW;

struct ncurses_screen
{
	NCURSES_WINDOW *main_window;
	NCURSES_WINDOW *child_window[WIN_MAX_WINDOWS];
	int child_count;
	pthread_mutex_t screen_mutex;
};
typedef struct ncurses_screen NCURSES_SCREEN;


void win_destroy_screen(NCURSES_SCREEN *);
void win_destroy_window(NCURSES_WINDOW *);
NCURSES_SCREEN * win_init_screen(NCURSES_WINDOW_OPTS *opts);
NCURSES_WINDOW * win_create_window(NCURSES_WINDOW_OPTS *opts);
NCURSES_WINDOW * win_add_window(NCURSES_SCREEN *, NCURSES_WINDOW *);

void win_init(void);
NCURSES_SCREEN *edpvr_win_init(DEVICE_STRUCT *);
int win_screen_printw(NCURSES_SCREEN *, const char *, ...);
int win_screen_vprintw(NCURSES_SCREEN *, const char *, va_list);

int generic_vprintw(DEVICE_STRUCT *, const char *, va_list);
void win_screen_update_all(NCURSES_SCREEN *);


void win_tuner_read_status(TUNER_STRUCT *);
void win_tuner_write_status(TUNER_WRITEPASS_STRUCT *);

#endif
